#include<stdio.h>
#include<sys/wait.h>
#include<stdlib.h>
#include<unistd.h>

/*
child will exit
child process id:29343
Get child status=200
Get child status=2

wait作用：若子进程没有结束，父进程一直阻塞
 *
 */

int main(){
	pid_t pid;
	pid_t rpid;
	int status;
	pid = fork();
	if(pid < 0){
		perror("fork");
	}else if(pid == 0){

		sleep(5);
		printf("child will exit\n");
		exit(2);

	}else if(pid > 0){

		rpid = wait(&status);
		printf("child process id:%d\n", (int)rpid);
		// 十进制展示是512  十六进制展示是200
		printf("Get child status=%x\n", status);
		printf("Get child status=%d\n", WEXITSTATUS(status));
	}

	sleep(3);
}
